/**
 * Created by lenovo on 2017/5/12.
 */
import React from 'react';
import CommodityMessageDetails from  './commodityMessageDetails.react';


class CommodityMessage extends React.Component{
    constructor(props){
        super(props);
    }
    render() {
        const commodity = this.props.commodityData;
        //循环展示组件的时候需要给每个组件一个key值
        //解决方案：使用new Date()函数生成独一无二的id, key={+new Date() + index}
        if(commodity instanceof Array && commodity !== []){
            try{
                const picList = commodity.map(
                    (item, index)=>{
                        return (
                            <CommodityMessageDetails
                                key={new Date()+index}
                                commodityData={item}
                            />
                        );
                    }
                );
                return(
                    <div className="commodityContainer">
                        {picList}
                    </div>
                );
            }catch(e){
                console.log('error in product'+e);
            }
        }else{
            return(
                <div className="">没有商品</div>
            );
        }

    }
}

export default CommodityMessage;